package com.cmc.cloud.cmclink.doc.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.vo.voyagebsapodvo.VoyageBsaPodCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.voyagebsapodvo.VoyageBsaPodPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.voyagebsapodvo.VoyageBsaPodRespVO;
import com.cmc.cloud.cmclink.doc.vo.voyagebsapodvo.VoyageBsaPodUpdateReqVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

import org.springframework.validation.annotation.Validated;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.*;
import java.util.*;


import com.cmc.cloud.cmclink.doc.entity.VoyageBsaPodDO;
import com.cmc.cloud.cmclink.doc.service.VoyageBsaPodService;


/**
 * 目的港舱位分配前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 目的港舱位分配")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/bsaPod")
public class VoyageBsaPodController {

    @Resource
    private VoyageBsaPodService voyageBsaPodService;

    @Operation(summary = "创建目的港舱位分配")
    @PostMapping("/create")
    @PreAuthorize("@ss.hasPermission({'doc:setupBSAExport:PODBSA:add','doc:setupBSAImport:PODBSA:add','doc:setupBSAExportTemplate:PODBSA:add','doc:setupBSAImportTemplate:PODBSA:add'})")
    public CommonResult<Void> createVoyageBsaPod(@Valid @RequestBody VoyageBsaPodCreateReqVO createReqVO) {
        voyageBsaPodService.createVoyageBsaPod(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新目的港舱位分配")
    @PostMapping("/update")
    @PreAuthorize("@ss.hasPermission({'doc:setupBSAExport:PODBSA:edit','doc:setupBSAImport:PODBSA:edit','doc:setupBSAExportTemplate:PODBSA:edit','doc:setupBSAImportTemplate:PODBSA:edit'})")
    public CommonResult<Void> updateVoyageBsaPod(@Valid @RequestBody VoyageBsaPodUpdateReqVO updateReqVO) {
        voyageBsaPodService.updateVoyageBsaPod(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除目的港舱位分配")
    @PostMapping("/delete/{id}")
    @PreAuthorize("@ss.hasPermission({'doc:setupBSAExport:PODBSA:delete','doc:setupBSAImport:PODBSA:delete','doc:setupBSAExportTemplate:PODBSA:delete','doc:setupBSAImportTemplate:PODBSA:delete'})")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Void> deleteVoyageBsaPod(@PathVariable("id") Long id) {
        voyageBsaPodService.deleteVoyageBsaPod(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得目的港舱位分配")
    @GetMapping("/get/{id}")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<VoyageBsaPodRespVO> getVoyageBsaPod(@PathVariable("id") Long id) {
        VoyageBsaPodDO voyageBsaPod = voyageBsaPodService.getVoyageBsaPod(id);
        return CommonResult.success(BeanUtil.copyProperties(voyageBsaPod, VoyageBsaPodRespVO.class));
    }

    @Operation(summary = "根据主信息id获得目的港舱位分配")
    @GetMapping("/getByMainId/{mainId}")
    @UseResponsePropertyAdvice
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<List<VoyageBsaPodRespVO>> getVoyageBsaPodByMainId(@PathVariable("mainId") Long id) {
        List<VoyageBsaPodDO> bsaPodDOList = voyageBsaPodService.getVoyageBsaPodByMainId(id);
        return CommonResult.success(BeanUtil.copyToList(bsaPodDOList, VoyageBsaPodRespVO.class));
    }

    @Operation(summary = "获得目的港舱位分配列表")
    @GetMapping("/list")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<VoyageBsaPodRespVO>> getVoyageBsaPodList(@RequestParam("ids") Collection<Long> ids) {
        List<VoyageBsaPodDO> list = voyageBsaPodService.getVoyageBsaPodList(ids);
        return CommonResult.success(BeanUtil.copyToList(list, VoyageBsaPodRespVO.class));
    }

    @Operation(summary = "获得目的港舱位分配分页")
    @GetMapping("/page")
    @UseResponsePropertyAdvice
    public CommonResult<PageResult<VoyageBsaPodRespVO>> getVoyageBsaPodPage(@Valid @RequestBody VoyageBsaPodPageReqVO pageVO) {
        PageResult<VoyageBsaPodDO> pageResult = voyageBsaPodService.getVoyageBsaPodPage(pageVO);
        List<VoyageBsaPodRespVO> results = BeanUtil.copyToList(pageResult.getList(), VoyageBsaPodRespVO.class);
        return CommonResult.success(new PageResult<>(results, pageResult.getTotal()));
    }
}
